<template>
	<view style="padding: 30rpx;height: 100%;overflow: auto;">
		<view class="header">
			<u-avatar :src="uInfo.avatar"></u-avatar>
			<view class="" style="flex: 1;margin-left: 20rpx;">
				<view class="">
					{{uInfo.username || '--'}}
				</view>
				<view class="" style="color: #7B7878;font-size: 24rpx;">

				</view>
			</view>
			<view class="btn" @click="toUInfo">
				设置
			</view>
		</view>
		<view class="tabs">
			<view class="tab" @click="toPay">
				<view class="" style="font-weight: 600;font-size: 34rpx;margin-bottom: 6rpx;">
					{{total}}
				</view>
				<view class="" style="color: #95979B;font-size: 28rpx;">
					明细记录
				</view>
			</view>
			<view class="tab" @click="toMyFabu">
				<view class="" style="font-weight: 600;font-size: 34rpx;margin-bottom: 6rpx;">
					{{list.length}}
				</view>
				<view class="" style="color: #95979B;font-size: 28rpx;">
					我的发布
				</view>
			</view>
			<view class="tab" @click="toHistory">
				<view class="" style="font-weight: 600;font-size: 34rpx;margin-bottom: 6rpx;">
					{{total1}}
				</view>
				<view class="" style="color: #95979B;font-size: 28rpx;">
					浏览记录
				</view>
			</view>
		</view>
		<view class="tabs">
			<view class="tab" @click="toPay">
				<image src="../../static/my/pic1.png" mode=""></image>
				<view class="">
					明细记录
				</view>
			</view>
			<view class="tab" @click="toHistory">
				<image src="../../static/my/pic2.png" mode=""></image>
				<view class="">
					浏览记录
				</view>
			</view>
			<view class="tab" @click="toSc">
				<image src="../../static/my/pic3.png" mode=""></image>
				<view class="">
					我的收藏
				</view>
			</view>
			<view class="tab" @click="toSetting">
				<image src="../../static/my/pic4.png" mode=""></image>
				<view class="">
					个人设置
				</view>
			</view>
		</view>
		<view class="items">
			<view class="" style="padding: 30rpx;padding-bottom: 0;font-weight: 600;">
				我的发布
			</view>
			<u-empty mode="data" icon="http://cdn.uviewui.com/uview/empty/data.png" v-if="list.length==0">
			</u-empty>
			<view class="" style="height:30rpx;" v-if="list.length==0">

			</view>
			<view class="item" v-for="(item,index) in list" :key="index" @click="toDetail(item)">
				<view class="top">
					<!-- <image :src="uInfo.avatar" mode=""></image> -->
					<u-avatar :src="item.userInfo.avatar"></u-avatar>
					<view class="" style="flex: 1;margin-left: 20rpx;">
						<view class="" v-if="item.userInfo">
							{{item.userInfo.username || '--'}}
						</view>
						<view class="" style="color: #7B7878;font-size: 24rpx;">
							{{formatTimestamp(item.createtime)}}
						</view>
					</view>
					<image src="../../static/home/more.png" mode="" class="more"></image>
				</view>
				<view class="" style="margin: 10rpx 0;">
					{{item.title}}
				</view>
				<view class="imgs">
					<image :src="img" mode="" v-for="(img,ind) in item.images" :key="ind"></image>
				</view>
				<view class="" style="text-align: right;padding:0 20rpx;">
					<text v-if="item.status==0">审核中...</text>
					<text v-if="item.status==1" style="color: grey;">审核通过</text>
					<text v-if="item.status==2" style="color:red">审核拒绝</text>
				</view>
			</view>
		</view>
		<view class="" style="opacity: 0;font-size: 60rpx;">
			1
		</view>
	</view>
</template>

<script>
	import {
		infoList,
		userMoneyLog,
		myViewInfo
	} from "@/request/api/tiezi.js"
	export default {
		data() {
			return {
				uInfo: {},
				list: [],
				total: 0,
				total1: 0
			}
		},
		onShow() {
			this.uInfo = uni.getStorageSync("userInfo");
			infoList({
				user_id: this.uInfo.id,
				pageSize: 100
			}).then(res => {
				this.list = res.data.data.map(item => {
					item.images = item.images.split(',');
					return item
				})
				console.log(this.list)
			})
			userMoneyLog().then(res => {
				this.total = res.data.result.total;
			})
			myViewInfo().then(res => {
				this.total1 = res.data.total;
			})
		},
		methods: {
			toDetail(item) {
				uni.setStorageSync("goodInfo", item)
				uni.navigateTo({
					url: "/pages/detail/detail1?id=" + item.id
				})
			},
			formatTimestamp(timestamp) {
				// 创建 Date 对象
				const date = new Date(timestamp * 1000); // 将时间戳转换为毫秒

				// 获取年份、月份、日期、小时、分钟、秒
				const year = date.getFullYear();
				const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始，需要加1
				const day = String(date.getDate()).padStart(2, '0');
				const hour = String(date.getHours()).padStart(2, '0');
				const minute = String(date.getMinutes()).padStart(2, '0');
				const second = String(date.getSeconds()).padStart(2, '0');

				// 返回格式化的日期时间字符串
				return `${year}-${month}-${day}`;
			},
			toSetting() {
				uni.navigateTo({
					url: "/pages/setting/setting"
				})
			},
			toMyFabu() {
				uni.navigateTo({
					url: "/pages/my/fabu"
				})
			},
			toUInfo() {
				uni.navigateTo({
					url: "/pages/uInfo/uInfo"
				})
			},
			toSc() {
				uni.navigateTo({
					url: "/pages/my/sc"
				})
			},
			toPay() {
				uni.navigateTo({
					url: "/pages/pay/pay"
				})
			},
			toHistory() {
				uni.navigateTo({
					url: "/pages/my/history"
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.items {
		background-color: white;
		border-radius: 20rpx;
		margin-top: 30rpx;

		.item {
			border-radius: 20rpx;
			background-color: white;
			padding: 30rpx;
			margin-top: 10rpx;

			.top {
				display: flex;
				align-items: center;

				image {
					width: 80rpx;
					height: 80rpx;
					border-radius: 100px;
					margin-right: 20rpx;
				}

				.more {
					width: 40rpx;
					height: 10rpx;
					margin-right: 0;
				}
			}

			.imgs {
				display: flex;
				justify-content: space-between;
				flex-wrap: wrap;

				image {
					width: 190rpx;
					height: 190rpx;
					border-radius: 30rpx;
					margin-bottom: 10rpx;
				}
			}
		}
	}

	.tabs {
		display: flex;
		border-radius: 20rpx;
		background-color: white;
		padding: 30rpx 0;
		margin-top: 30rpx;

		.tab {
			flex: 1;
			display: flex;
			flex-direction: column;
			align-items: center;

			image {
				width: 58rpx;
				height: 58rpx;
				margin-bottom: 10rpx;
			}
		}
	}

	.header {
		display: flex;
		align-items: center;

		image {
			width: 80rpx;
			height: 80rpx;
			border-radius: 100px;
			margin-right: 20rpx;
		}

		.btn {
			background-color: #2DBC26;
			color: white;
			padding: 6rpx 24rpx;
			border-radius: 100px;
			font-size: 26rpx;
		}
	}
</style>